package com.rabbitmq.rabbit;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.Date;
import java.util.Map;

/**
 * @Author: TongRui乀
 * @Date: 2020-07-23 10:13
 * @description：
 */
@Slf4j
@Service
public class DelayOrderListener {



    @RabbitListener(queues = "${order.delay.queue.name}", containerFactory = "singleListenerContainer")
    public void process(Message message, @Headers Map<String, Object> headers, Channel channel) throws IOException {

        log.info("【 监听到延时队列消息】 - 【消费时间】 - [{}]- 【订单内容】 - [{}]",  new Date(),new String(message.getBody()));
        // 判断订单是否已经支付，如果支付则；否则，取消订单（逻辑代码省略)
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        // 手动ack
        // 手动签收
        channel.basicAck(deliveryTag, false);
        System.out.println("执行结束....");

    }


}
